import 'package:flutter/material.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class JoyBlocUtil {



  static getAppBloc<C extends BlocBase<S>, S>(
  {required Widget builder(context, state),
  PreferredSizeWidget? appBar,
  required C create(context),
  BlocBuilderCondition<S>? buildWhen,
  Color? backgroundColor,
  bool resizeToAvoid = true}) {
  return Container(
  child: Scaffold(
  resizeToAvoidBottomInset: resizeToAvoid,
  backgroundColor: backgroundColor ?? Colors.transparent,
  appBar: appBar,
  body: Container(
  color: Colors.white,
  child: BlocProvider(
  create: (_) => create(_),
  child: BlocBuilder<C, S>(
  buildWhen: buildWhen,
  builder: (context, state) {
  /// Look here: refresh component!
  return builder(context, state);
  },
  ),
  ),
  )),
  );
  }

  static getAppNoBarBloc<C extends BlocBase<S>, S>(
  {required C create(context),
  BlocBuilderCondition<S>? buildWhen,
  required Widget builder(context, state),
  Color? backgroundColor}) {
  return Container(
  color: backgroundColor ?? Colors.white,
  child: BlocProvider(
  create: (_) => create(_),
  child: BlocBuilder<C, S>(
  buildWhen: buildWhen,
  builder: (context, state) {
  ///看这看这：刷新组件！
  return builder(context, state);
  },
  ),
  ));
  }



  
}